package edu.caltech.cs.cs141.CopilotWeb.server;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;


import edu.caltech.cs.cs141.CopilotWeb.client.TripInterface;
import edu.caltech.cs.cs141.CopilotWeb.shared.ClientTripHeader;
import edu.caltech.cs.cs141.CopilotWeb.shared.TripDataClient;

public class TripInterfaceImpl extends RemoteServiceServlet implements
		TripInterface {

	public List<ClientTripHeader> getTripList(String username) {
		ClientTripHeader cth = null;
		List<ClientTripHeader> cthlist = new ArrayList<ClientTripHeader>();
		ObjectifyService.register(TripData.class);
		Objectify ofy = ObjectifyService.begin();
		Query<TripData> q = ofy.query(TripData.class).filter("username", username);
		for (TripData trip: q) {
			cth = trip.toClientHeader();
			cthlist.add(cth);
		}
		return cthlist;
	}

	public TripDataClient getTrip(long tripid) {
		Objectify ofy = ObjectifyService.begin();
		TripDataClient tc = null;
		TripData trip = ofy.get(TripData.class, tripid);
		tc = trip.toClient();
		return tc;
	}

}
